package com.qitmiaojie.service.impl;

import com.qitmiaojie.pojo.Malfunction;
import com.qitmiaojie.service.SendEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@Service
public class SendEmailServiceImpl implements SendEmailService {

    private String from = "1741672901@qq.com";	 // 发送人
    private String to = "1741672901@qq.com";	 // 接收人
    private String subject = "您收到了一条报修信息";		 // 邮件主题
    private String text = "测试邮件正文";	 	// 邮件内容


    @Autowired
    private JavaMailSender javaMailSender;


    @Override
    public void sendEmail(Malfunction malfunction) throws MessagingException {
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage,true);

        mimeMessageHelper.setFrom(from);
        mimeMessageHelper.setTo(to);
        mimeMessageHelper.setText("报修地点："+malfunction.getFloor() +" "
                +malfunction.getAddress() + "报修人的手机号："+
                malfunction.getPhone()+" " +"报修故障为"+ malfunction.getName() + "  "+malfunction.getDesc() );

        javaMailSender.send(mimeMessage);
    }
}
